import React from 'react';
import { connect } from 'dva';
import { Card, Row, Col } from 'antd';



import DefinitionList from '../../../components/DefinitionList'
class PortfolioAssets extends React.Component {
    state = {
        data: this.props.portfolioAssets
    }
    componentDidMount() {
        this.fetchData(this.props)
    }
    componentWillReceiveProps(nextProps) {
        if ((nextProps.lPortId !== this.props.lPortId) || (nextProps.date !== this.props.date)) {
            this.fetchData(nextProps)
        }
        if (nextProps.portfolioAssets !== this.props.portfolioAssets) {
           
            this.setState({
                data: nextProps.portfolioAssets,
            })
        }
    }
    //fetchData  查询数据
    fetchData = (props) => {
        props.dispatch({
            type: 'combinatorialAnalysis/getPortfolioAssets2',
            payload: props
        })
    }

    render() {
        const {list}=this.state.data
        const  data=[
            {
                name:'组合资产规模',
                value:list&&list.find(item=>item.name==='总资产')&&list.find(item=>item.name==='总资产').lastMoney
            },
            {
                name:'组合负债规模',
                value:list&&list.find(item=>item.name==='负债')&&list.find(item=>item.name==='负债').lastMoney
            },
            {
                name:'组合净值规模',
                value:list&&list.find(item=>item.name==='净资产')&&list.find(item=>item.name==='净资产').lastMoney
            }
        ]
        
        
        return (
            <Card bordered={false} className="portfolioAssets">
            {
                data.map((item,i)=>(
                    <DefinitionList key={i} name={item.name} value={<span><b>{item.value}</b>亿</span>} />
                ))
            }
               
            </Card>

        );
    }
}
PortfolioAssets.defaultProps = {
    lPortId: null,
    lastDate: null,
    portfolioAssets: {
        "fieldList": [
            {
                "id": "name",
                "name": "组合资产规模"
            },
            {
                "id": "firstMoney",
                "name": "期初金额/亿"
            },
            {
                "id": "lastMoney",
                "name": "期末金额/亿"
            },
            {
                "id": "increase",
                "name": "较上期/亿"
            }
        ],
        "list": [
            {
                "id": "1",
                "name": "总资产",
                "firstMoney": 1020,
                "lastMoney": 2340,
                "increase": 0.78
            }
        ]
    }
}
export default connect()(PortfolioAssets)